{include file="public/header"}
<body>

<div class="ht-drawer-main" id="app" style="background-color: #ffffff;padding-bottom: 65px">
    <div class="ht-form" v-cloak>
        <el-form :model="editData" label-width="120px" size="small">
            <el-form-item label="标题">
                <el-input type="text" placeholder="标题" v-model="editData.title"></el-input>
            </el-form-item>
            <el-form-item style="padding-bottom: 70px" label="详情">
                <ht-editor v-model="editData.content"></ht-editor>
            </el-form-item>
            <div class="submit-button">
                <el-form-item style="padding-top: 15px;padding-left: 15px">
                    <el-button @click="goBack">取消</el-button>
                    <el-button type="primary" @click="onSubmit">提交</el-button>
                </el-form-item>
            </div>
        </el-form>
    </div>
</div>
{include file="public/common"}
{include file="public/editor"}
<script>
    let vs ;
    let del_url = "{:url('Archives/del')}";
    let add_url = "{:url('Archives/add')}";
    let index_url = "{:url('Archives/index')}";
    new Vue({
        el: "#app",
        data: function () {
            return {
                showDialog: false,
                arctypeList: [],
                activeTab: 'first',
                tableData: [],
                is_edit: false,
                editData: {},
                editDataTemp: {},
                content: '编辑',
                total: 0,
                page: 1,
                limit: 10,
                userList: [],
                sourceList: [],
                categoryList: [],
                phpList:[],
                fileManage:false,
                activeName:'first',
                showVideo:false,
                editor1:''
            }
        },
        created: function () {
            vs = this;
            vs.getCategory()
        },
        methods: {
            videoSuccess(path) {
                console.log(path)
                if (path) {
                    vs.editData.video = path
                }
                vs.showVideo = false
            },
            getCategory() {
                Api.request("{:url('category/all')}").then(res=>{
                    vs.categoryList = res.data
                })
            },
            imageManageClose(path) {
                this.showDialog = false;
            },
            imageSubmit(path) {
                console.log("path", path)
                this.editDataTemp.litpic = path[0]
                this.editData.litpic = path[0]
                this.showDialog = false;
            },
            imageManage() {
                this.showDialog = true;
            },
            uploadSuccess(litpic, value) {
                this.editDataTemp.litpic = litpic
                this.editData.litpic = litpic
            },

            changeStatus: function (e, id) {
                axios.post("{:url('Archives/ArchivesStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            changeMenuStatus: function (e, id) {
                axios.post("{:url('Auth/menuStatus')}", {id: id}).then((res) => {
                    if (res.data.code == 1) {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1000,
                        })
                    } else {
                        this.$message({
                            message: res.data.msg,
                            type: 'error',
                            duration: 1500,
                            onClose: function () {
                                location.reload()
                            }
                        })
                    }
                })
            },
            onSubmit() {
                var that = this
                $.post(add_url, that.editData, function (res) {
                    if (res.code == 1) {
                        that.showSuccessMsgCall(()=>{
                            parent.vm.getData()
                            parent.layer.closeAll()
                        })
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },

            getData: function () {
                var that = this
                that.searchType = {
                    title: 'like'
                };
                $.post(index_url, {
                    limit: that.limit,
                    page: that.page,
                    search_key: that.searchKey,
                    search_type: that.searchType
                }, function (res) {
                    if (res.code == 1) {
                        that.tableData = res.data.data
                        that.total = res.data.total
                    } else {
                        that.showErrorMsg(res.msg)
                    }
                })
            },
            doAdd: function () {
                this.is_edit = true
                this.content = '添加'
                this.editData = {}
            },
            edit: function (data) {
                this.is_edit = true
                this.content = '编辑'
                this.editData = data

                console.log(data)
            },
            goBack: function () {
                parent.Helper.close()
            },
            del: function (data) {
                var that = this
                that.$confirm('确定删除么?', '提示', {
                    type: 'warning',
                    lockScroll: false
                }).then(() => {
                    $.post(del_url, {id: data.id}, function (res) {
                        if (res.code == 1) {
                            that.showSuccessMsgCall(function () {
                                that.getData()
                                that.getCategory()
                            })
                        } else {
                            that.showErrorMsg(res.msg)
                        }
                    })
                })
            },
            handleSizeChange: function (e) {
                this.limit = e
            },
            handleCurrentChange: function (e) {
                this.page = e
            }
        },
        watch: {

        }
    })
</script>
</body>
</html>